<?php

use App\Http\Controllers\Admin\{
    AdvController,
    ArticleController,
    BannerController,
    ConfigController,
    CacheController,
    CategoryController,
    EmailController,
    LoginController,
    NavController,
    TagsController,
};
use App\Http\Controllers\Admin\miniapp\{
    SettingsController as AdminMiniappSettingsController,
    BannerController as AdminMiniappBannerController,
    GoodsCategoryController as AdminMiniappGoodsCategoryController,
    GoodsController as AdminMiniappGoodsController,
    OrderController as AdminMiniappOrderController,
    UserController as AdminMiniappUserController
};
use App\Http\Controllers\Miniapp\{
    LoginController as MiniappLoginController,
    BannerController as MiniappBannerController,
    CategoryController as MiniappGoodsCategoryController,
    GoodsController as MiniappGoodsController,
    OrderController as MiniappOrderController,
    UserController as MiniappUserController
};
use App\Http\Controllers\Uploader;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

// Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
//     return $request->user();
// });

// Route::namespace('Admin')->prefix('admin')->group(function () {
//     Route::get('login', [LoginController::class, 'login'])->name('admin.login');
//     Route::get('register', [LoginController::class, 'register'])->name('admin.register');
// });



Route::post('uploader', [Uploader::class, 'upload'])->name('uploader');

Route::prefix('admin')->group(function () {
    Route::post('login', [LoginController::class, 'login'])->name('login');
    Route::get('config', [ConfigController::class, 'index'])->name('config.index');
    Route::any('sendmail', EmailController::class)->name('sendmail');
    Route::post('forget', [LoginController::class, 'forget'])->name('forget');

    Route::middleware(['jwt.retoken:admin'])->group(function () {
        Route::post('config', [ConfigController::class, 'store'])->name('config.store');
        Route::post('clearCache', [CacheController::class, 'clear'])->name('cache.clear');
        Route::post('admin', [LoginController::class, 'repassword'])->name('admin.repassword');

        Route::prefix('miniapp')->group(function () {
            Route::get('settings', [AdminMiniappSettingsController::class, 'index']);
            Route::post('settings', [AdminMiniappSettingsController::class, 'update']);

            Route::apiResource('banner', AdminMiniappBannerController::class)->where(['banner' => '\d+']);
            Route::delete('banner/batch', [AdminMiniappBannerController::class, 'batchDelete']);

            Route::apiResource('user', AdminMiniappUserController::class)->where(['user' => '\d+']);
            Route::delete('user/batch', [AdminMiniappUserController::class, 'batchDelete']);

            Route::apiResource('category', AdminMiniappGoodsCategoryController::class)->where(['category' => '\d+']);
            Route::delete('category/batch', [AdminMiniappGoodsCategoryController::class, 'batchDelete']);
            Route::apiResource('goods', AdminMiniappGoodsController::class)->where(['goods' => '\d+']);
            Route::delete('goods/batch', [AdminMiniappGoodsController::class, 'batchDelete']);

            Route::apiResource('order', AdminMiniappOrderController::class)->where(['order' => '\d+']);
            Route::delete('order/batch', [AdminMiniappOrderController::class, 'batchDelete']);
        });

        Route::apiResource('nav', NavController::class)->where(['nav' => '\d+']);
        Route::delete('nav/batch', [NavController::class, 'batchDelete']);

        Route::apiResource('banner', BannerController::class)->where(['banner' => '\d+']);
        Route::delete('banner/batch', [BannerController::class, 'batchDelete']);

        Route::apiResource('article', ArticleController::class)->where(['article' => '\d+']);
        Route::delete('article/batch', [ArticleController::class, 'batchDelete']);

        Route::apiResource('adv', AdvController::class)->where(['adv' => '\d+']);
        Route::delete('adv/batch', [AdvController::class, 'batchDelete']);

        Route::apiResource('category', CategoryController::class)->where(['category' => '\d+']);
        Route::delete('category/batch', [CategoryController::class, 'batchDelete']);

        Route::apiResource('tags', TagsController::class)->where(['tag' => '\d+']);
        Route::delete('tags/batch', [TagsController::class, 'batchDelete']);
    });
});

Route::prefix('miniapp')->group(function () {
    Route::post('code/{code}', [MiniappLoginController::class, 'code']);
    Route::post('login', [MiniappLoginController::class, 'login']);

    Route::get('banner', [MiniappBannerController::class, 'index']);
    Route::get('recommendlist', [MiniappGoodsController::class, 'recommendList']);

    Route::get('category', [MiniappGoodsCategoryController::class, 'index']);
    Route::get('goods', [MiniappGoodsController::class, 'index']);
    Route::get('goods/{id}', [MiniappGoodsController::class, 'show'])->where(['id' => '\d+']);

    Route::middleware(['jwt.retoken:miniapp'])->group(function () {
        Route::get('user', [MiniappUserController::class, 'show'])->where(['id' => '\d+']);
        Route::post('logout', [MiniappUserController::class, 'logout']);

        Route::get('order', [MiniappOrderController::class, 'index']);
        Route::get('order/{id}', [MiniappOrderController::class, 'show'])->where(['id' => '\d+']);
    });
});
